{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4f03a991-0ee9-4bce-8946-1c4716378bdb",
   "metadata": {},
   "outputs": [],
   "source": [
    "student1 = {'name':'Bob','age':21}\n",
    "student2 = {'name':'Alice','age':22}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6dbd9e7e-cbc1-4de9-b8c6-f20c8a14a736",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 定义一个函数输出两个学生信息\n",
    "def print_info(student):\n",
    " \n",
    "    print('姓名：%s，年龄：%d' % (student['name'],student['age']))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "00ae9477-1d5d-486f-a48d-2edf02d0049a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 输出某一个学生的信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fe49e1bc-3e3d-4704-8aae-81a09fb350a0",
   "metadata": {},
   "outputs": [],
   "source": [
    "print_info(student1)\n",
    "print_info(student2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a7dbab1f-069d-436a-bb28-0d4793d36dff",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0f2aa645-4731-4125-9b23-9ab3d45cd8a9",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "67cc0fb4-41fe-4cb2-9bc8-43218be38770",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "7974cc07-e871-40b2-9dc1-bc2729d33afc",
   "metadata": {},
   "outputs": [],
   "source": [
    "class Student(): # 定义一个类\n",
    "    def __init__(self,name,age,weight):\n",
    "        self.__name = name\n",
    "        self.age = age\n",
    "        self.__weight = weight\n",
    "    def info(self): # 定义一个方法\n",
    "        print('姓名：%s，年龄：%d，体重：%d' % (self.__name,self.age,self.__weight))\n",
    "    def change_age(self,new_age):\n",
    "        self.age = new_age\n",
    "        self.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "f6588ab7-a9f0-4efc-ba93-16d7bb7b09f9",
   "metadata": {},
   "outputs": [],
   "source": [
    "student1 = Student('John',22,65) # 类的实例化\n",
    "student2 = Student('Lisa',24,57)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "a24b5ce1-4853-4597-b232-f6efef30afe4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "姓名：John，年龄：22，体重：65\n",
      "姓名：Lisa，年龄：24，体重：57\n"
     ]
    }
   ],
   "source": [
    "student1.info()\n",
    "student2.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "24c0884c-7db2-41cc-a650-c2f4e590ad79",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "姓名：Lisa，年龄：38，体重：57\n"
     ]
    }
   ],
   "source": [
    "student2.change_age(38)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "400d8399-c8fd-4ae7-bf32-31caadfb1a20",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "38"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "student2.age"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "730c944f-a5f9-4cbb-8e2e-783f7c8fb751",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
